home *** CD-ROM | disk | FTP | other *** search
- Path: news.vcd.hp.com!koayst
- From: koayst@hpsglmx.sgp.hp.com (Koay Seng Tian)
- Newsgroups: comp.lang.c++
- Subject: Recursive Definition?
- Date: 16 Jan 1996 02:41:55 GMT
- Organization: Hewlett-Packard
- Message-ID: <4df39j$f80@news.vcd.hp.com>
- NNTP-Posting-Host: hpsgl4.sgp.hp.com
- X-Newsreader: TIN [version 1.2 021193BETA PL3]
-
- I have a problem in understanding the following C++ code which I have gotten
- from a book (C++ components and Algorithms by Scott R. Ladd). Please help!!
-
- class Switch()
- {
- public:
- Switch();
- Switch(int sw);
- Switch(const Switch & sw);
-
- Switch & operator = (int sw);
- Switch & operator = (const Switch & sw);
-
- static const Switch On;
- static const Switch Off;
-
- int IsOn();
- int IsOff();
-
- protected:
- int setting;
- };
-
- const Switch Switch::On = 1;
- const Switch Switch::Off = 0;
-
- What are the above two statements trying to initialize?
- It seems to me that they are sort of doing a recursive
- initialization. Please help!!!!
-
- Following are the rest of the code.
-
- Switch::Switch()
- {
- Setting = Off.Setting;
- }
-
- Switch::Switch(int sw)
- {
- if(sw == On.Setting)
- Setting = On.Setting;
- else
- Setting = Off.Setting;
- }
-
- Switch::Switch(const Switch & sw)
- {
- Setting = sw.Setting;
- }
-
- Switch & Switch::operator = (int sw)
- {
- if(sw == On.Setting)
- Setting = On.Setting;
- else
- Setting = Off.Setting;
-
- return *this;
- }
-
- Switch & Switch::operator = (const Switch & sw)
- {
- Setting = sw.Setting;
- return *this;
- }
-
-
- Seng Tian
- Regards
-